package com.itheima.job2;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //1.创建SocketServer对象并设置程序的端口号
        ServerSocket server = new ServerSocket(6666);
        //2.调用accept方法等待客户端连接
        Socket socket = server.accept();
        //3.通过socket通道获取字节输入流
        //4.当accept解阻塞，意味着有客户端连接，得到一个socket对象
        //5.获取输入流读取输入流的数据
        InputStream inputStream = socket.getInputStream();
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        String s = dataInputStream.readUTF();
        System.out.println(s);
        OutputStream os = socket.getOutputStream();
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeUTF("反馈信息");
        //6.告诉客户端写数据完毕
        socket.shutdownOutput();
        //7.释放资源
        server.close();
    }
}
